#include <bits/stdc++.h>
using namespace std;

using llt = long long;

int N;
string S;

int proc(){
    set<string> ss;
    for(int i=0;i<N-1;++i) ss.insert(S.substr(i, 2));
    return ss.size();
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(0);
    int nofakse; cin >> nofakse;
    while(nofakse--){
        cin >> N >> S;
        cout << proc() << endl;
    }
    return 0;
}